<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>获取URL参数, 并转换为对象类型</title>
</head>
<body>
  <script>
    function fn(str) {
      var obj = {}
      var arr1 = str.split('?')
      var arr2 = arr1[1].split('&')
      for(let i = 0; i < arr2.length; i++) {
        var res = arr2[i].split('=')
        obj[res[0]] = res[1]
      }
      return obj
    }
    console.log(fn('http://item.taobao.com/item.htm?a=1&b=2&c=&d=shmhm'))
  </script>
</body>
</html>